package com.cyh.mylib.impl;

import android.app.Application;
import android.content.Context;

import com.aries.library.fast.FastManager;
import com.aries.library.fast.retrofit.FastRetrofit;
import com.cyh.mylib.i.IBaseApp;
import com.jingewenku.abrahamcaijin.commonutil.application.AppUtils;


/**
 * @author 程延宏
 * @description:
 * @date :6/18 17:03
 */
public abstract class FastApp extends Application implements IBaseApp {
    public static int getRcyEmptyView = 0;
    public static int getRcyLoadingView = 0;
    private static Context mcontext;
    public static Context getAppContext() {
        return mcontext;
    }

    /**
     * 自定义接口
     * @return  接口地址
     */
    public abstract String getBaseUrl();

    @Override
    public void onCreate() {
        super.onCreate();
        mcontext = this;
        getRcyEmptyView = getRcyEmptyView();
        getRcyLoadingView = getRcyLoadingView();
        initFastLib();
        AppUtils.init(mcontext);
    }



    private void initFastLib() {
        AppImpl impl = getBaseAppImpl(getAppContext());
        ActivityControlImpl activityControl =  getActivityControlImpl();
        FastManager.getInstance()
                .setHttpRequestControl(getHttpRequestControlImpl())
                //设置Adapter加载更多视图--默认设置了FastLoadMoreView
                .setLoadMoreFoot(impl)
                //全局设置RecyclerView
                .setFastRecyclerViewControl(impl)
                //设置RecyclerView加载过程多布局属性
                .setMultiStatusView(impl)
                //设置全局网络请求等待Loading提示框如登录等待loading--观察者必须为FastLoadingObserver及其子类
                .setLoadingDialog(impl)
                //设置SmartRefreshLayout刷新头-自定加载使用BaseRecyclerViewAdapterHelper
                .setDefaultRefreshHeader(impl)
                //设置全局TitleBarView相关配置
                .setTitleBarViewControl(impl)
                //设置Activity滑动返回控制-默认开启滑动返回功能不需要设置透明主题
                //设置Activity/Fragment相关配置(横竖屏+背景+虚拟导航栏+状态栏+生命周期)
                .setActivityFragmentControl(activityControl)
                //配置BasisActivity 子类事件派发相关
                .setActivityDispatchEventControl(activityControl)
                //设置主页返回键控制-默认效果为2000 毫秒时延退出程序
                .setQuitAppControl(impl)
                //设置ToastUtil全局控制
                .setToastControl(impl);
        FastRetrofit.getInstance().setBaseUrl(getBaseUrl())
                .setCertificates()
                .setLogEnable(true,"HttpInfo")
                .setTimeout(30);
    }

}
